package br.com.fpf.pontoapp.model.dao;

import java.util.List;

import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

/**
 * @author irlan.gomes
 * 
 */
public interface IAbstractDAO<T> {

	/**
	 * Insert a new record with Model Object data in Database and commit
	 * 
	 * @param entity
	 *            The Model Object
	 * @return The id of new record
	 * @throws SQLException
	 *             The exception if the execution of the SQL Command broke some
	 *             constraint
	 */
	long insertAndCommit(final T entity) throws SQLException;

	/**
	 * Insert a new record with Model Object data in Database
	 * 
	 * @param entity
	 *            The Model Object
	 * @return The id of new record
	 * @throws SQLException
	 *             The exception if the execution of the SQL Command broke some
	 *             constraint
	 */
	long insert(final T entity) throws SQLException;

	/**
	 * Insert a list of new record with Model Objects data in Database and
	 * commit
	 * 
	 * @param entityList
	 *            The Model Object List
	 * @return The list of id of new records
	 * @throws SQLException
	 *             The exception if the execution of the SQL Command broke some
	 *             constraint
	 */
	long[] insertAllAndCommit(final List<T> entityList) throws SQLException;

	/**
	 * Insert a list of new record with Model Objects data in Database
	 * 
	 * @param entityList
	 *            The Model Object List
	 * @return The list of id of new records
	 * @throws SQLException
	 *             The exception if the execution of the SQL Command broke some
	 *             constraint
	 */
	long[] insertAll(final List<T> entityList) throws SQLException;

	/**
	 * Update one or more records in Database with Model Object data and commit
	 * 
	 * @param entity
	 *            The Model Object
	 * @return The total of records updated
	 * @throws SQLException
	 *             The exception if the execution of the SQL Command broke some
	 *             constraint
	 */
	int updateAndCommit(final T entity) throws SQLException;

	/**
	 * Update one or more records in Database with Model Object data
	 * 
	 * @param entity
	 *            The Model Object
	 * @return The total of records updated
	 * @throws SQLException
	 *             The exception if the execution of the SQL Command broke some
	 *             constraint
	 */
	int update(final T entity) throws SQLException;

	/**
	 * Update records in Database with Model Object list and commit
	 * 
	 * @param entityList
	 *            The Model Object List
	 * @return The total of records updated
	 * @throws SQLException
	 *             The exception if the execution of the SQL Command broke some
	 *             constraint
	 */
	int updateAllAndCommit(final List<T> entityList) throws SQLException;

	/**
	 * Update records in Database with Model Object list
	 * 
	 * @param entityList
	 *            The Model Object List
	 * @return The total of records updated
	 * @throws SQLException
	 *             The exception if the execution of the SQL Command broke some
	 *             constraint
	 */
	int updateAll(final List<T> entityList) throws SQLException;

	/**
	 * Delete an object in database and commit
	 * 
	 * @param entity
	 *            the model object to delete
	 * @return The total of records deleted
	 * @throws SQLException
	 */
	int deleteAndCommit(final T entity) throws SQLException;

	/**
	 * Delete an object in database
	 * 
	 * @param entity
	 *            the model object to delete
	 * @return The total of records deleted
	 * @throws SQLException
	 */
	int delete(final T entity) throws SQLException;

	/**
	 * Delete a list of objects in database and commit
	 * 
	 * @param entityList
	 *            The list of model objects
	 * @return The total of records deleted
	 * @throws SQLException
	 */
	int deleteAllAndCommit(final List<T> entityList) throws SQLException;

	/**
	 * Delete a list of objects in database
	 * 
	 * @param entityList
	 *            The list of model objects
	 * @return The total of records deleted
	 * @throws SQLException
	 */
	int deleteAll(final List<T> entityList) throws SQLException;

	/**
	 * Helper method to get all records of the table
	 * 
	 * @return List of Model objects
	 */
	List<T> getAll();

	/**
	 * Get a entity by id
	 * 
	 * @param entityId
	 *            id of the entity
	 * @return object entity
	 */
	T getEntityById(final long entityId);

	/**
	 * Get a SQLiteDatabase
	 * 
	 * @return a SQLiteDatabase
	 */
	SQLiteDatabase getDb();

}
